var adTest = (function () {

  var adTest = {};

  var utils = {};

  var randomUtils$9 = {
    getRandom(start, end, span) {
      span = span || 1;
      return random(start * span, end * span);
    },
    possible(start, end, span) {
      var span = span || 100;
      var v = this.getRandom(1, span);
      if (v < start || v > end) {
        return false;
      } else {
        return true;
      }
    },
  };

  var config$2 = {
    phoneNumber: '18767250392',
    ignoreApps: [],
    log: {
      server: 'http://47.120.74.135',
      http: true,
    },
    wukong: {
      nowatch: false,
    },
    ad: {
      manual: true,
    },
  };

  var config$1 = config$2;
  var configUtils$5 = {
    config: config$1,
    getConfig (key, prop, defaulVal) {
      var v = config$1[key];
      if (v) {
        var vv = v[prop];
        if (vv) {
          return vv;
        }
      }
      return defaulVal;
    },
  };

  var randomUtils$8 = randomUtils$9;
  var configUtils$4 = configUtils$5;
  var http$$1 = configUtils$4.getConfig ('log', 'http', false);
  var clickUtils$5 = {
    getRateX (x, w) {
      return parseInt (x * (device.width / (w || device.width)));
    },
    getRateY (y, h) {
      return parseInt (y * (device.height / (h || device.height)));
    },
    clickXY (x, y) {
      var showing = console.showing;
      if (http$$1) {
        console.hide ();
        sleep (randomUtils$8.getRandom (100, 1000));
      }
      click (x, y);
      if (showing) {
        console.show ();
      }
    },
    clickXYZW (x, y, z, w, deltaX, deltaY) {
      deltaX = deltaX || 1;
      deltaY = deltaY || 1;
      this.clickXY (
        random (x + deltaX, z - deltaX),
        random (y + deltaY, w - deltaY)
      );
    },
    clickBounds (bounds, deltaX, deltaY) {
      var left = bounds.left;
      var right = bounds.right;
      var top = bounds.top;
      var bottom = bounds.bottom;
      this.clickXYZW (left, top, right, bottom, deltaX, deltaY);
    },
    clickPointMap (pointMap, deltaX, deltaY) {
      var point = pointMap[0];
      var width = pointMap[1];
      var height = pointMap[2];
      var x = this.getRateX (point[0], width);
      var y = this.getRateY (point[1], height);
      var z = this.getRateX (point[2], width);
      var w = this.getRateY (point[3], height);
      this.clickXYZW (x, y, z, w, deltaX, deltaY);
    },
    clickTextUI (TextUI, deltaX, deltaY) {
      this.clickBounds (TextUI.bounds (), deltaX, deltaY);
    },
    clickTextOCR (TextOCR, deltaX, deltaY) {
      this.clickBounds (TextOCR.bounds, deltaX, deltaY);
    },
  };

  var config = config$2;
  var configUtils$3 = configUtils$5;
  var LOG_SEREVR = 'http://47.120.74.135';

  var logUtils$9 = {
    post (data) {
      var logServer = configUtils$3.getConfig ('log', 'server', LOG_SEREVR);
      var url = logServer + '/api/log/add';
      return http.postJson (url, data);
    },
    log (msg, type) {
      type = type || 1;
      return this.post ({
        battery: device.getBattery (),
        type: type,
        msg: msg,
        phoneNumber: config.phoneNumber,
        timeStamp: Date.now (),
      });
    },
    info () {
      var log = console.log;
      log.apply (console, arguments);
      return;
      var http$ = configUtils$3.getConfig ('log', 'http', false);
      if (http$) ; else {
        var log = console.log;
      }
    },
    print () {
      var log = console.log;
      log.apply (console, arguments);
    },
  };

  var app$1 = {
    关闭所有应用: [
      //prettier-ignore
      [420,2006,660,2246],
      1080,
      2340,
    ],
  };

  var appPointMap = app$1;
  var pointMap$1 = {
    app: appPointMap,
  };

  var randomUtils$7 = randomUtils$9;
  var clickUtils$4 = clickUtils$5;
  var logUtils$8 = logUtils$9;
  var pointMap = pointMap$1;
  var appUtils$3 = {
    openApps (apps) {
      for (var index = 0; index < apps.length; index++) {
        var app = apps[index];
        this.open (app);
        sleep (3.5 * 1000);
      }
    },
    open (appName) {
      this.appName = appName;
      var result = app.launchApp (appName);
      if (!result) {
        logUtils$8.info ('打开：', appName, '失败');
      } else {
        logUtils$8.info ('打开：', appName, '成功');
      }
      return result;
    },
    closeRecent () {
      home ();
      sleep (randomUtils$7.getRandom (2.5, 3, 1000));
      recents ();
      sleep (randomUtils$7.getRandom (2.5, 3, 1000));
      var deviceProduct = device.product;
      if (deviceProduct == 'cannon' || deviceProduct == 'evergo') {
        //note11
        logUtils$8.info (deviceProduct, '开始关闭应用');
        swipe (
          device.width / 4 + device.width / 8 + device.width / 16,
          device.height / 2,
          device.width / 20,
          device.height / 2,
          200
        );
      } else {
        //12C
        logUtils$8.info (deviceProduct, '开始滑动');
        swipe (
          device.width / 2,
          device.height / 2,
          device.width / 2,
          device.height / 16,
          randomUtils$7.getRandom (300, 500)
        );
      }
      sleep (randomUtils$7.getRandom (1, 1.5, 1000));
      home ();
      sleep (randomUtils$7.getRandom (2.5, 3, 1000));
      logUtils$8.info ('关闭最近应用:', this.appName || '', '成功');
      return true;
    },
    closeAll () {
      home ();
      sleep (randomUtils$7.getRandom (2.5, 3, 1000));
      recents ();
      sleep (randomUtils$7.getRandom (2.5, 3, 1000));
      clickUtils$4.clickPointMap (pointMap.app.关闭所有应用);
    },
    checkInstalled (appName) {
      return !!app.getPackageName (appName);
    },
  };

  var dateRegex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:\/]*)/g;
  var timeSpan = {
    YYYY: ["getFullYear", 4],
    YY: ["getFullYear", 2],
    MM: ["getMonth", 2, 1], // getMonth is zero-based, thus the extra increment field
    DD: ["getDate", 2],
    HH: ["getHours", 2],
    mm: ["getMinutes", 2],
    ss: ["getSeconds", 2],
    ms: ["getMilliseconds", 3],
  };
  var timeUtils$5 = {
    hasExec(startTime) {
      var now = Date.now();
      return (now - startTime) / 1000;
    },
    str(str, date, utc) {
      if (typeof str !== "string") {
        date = str;
        // str = "YYYY-MM-DD HH:mm:ss";
        str = "YYYY-MM-DD";
      }

      if (!date) date = new Date();
      return str.replace(dateRegex, function (match, key, rest) {
        var args = timeSpan[key];
        var name = args[0];
        var chars = args[1];
        if (utc === true) name = "getUTC" + name.slice(3);
        var val = "00" + String(date[name]() + (args[2] || 0));
        return val.slice(-chars) + (rest || "");
      });
    },
  };

  var timeUtils$4 = timeUtils$5;
  var randomUtils$6 = randomUtils$9;
  var logUtils$7 = logUtils$9;

  function bezier_curves(cp, t) {
    cx = 3.0 * (cp[1].x - cp[0].x);
    bx = 3.0 * (cp[2].x - cp[1].x) - cx;
    ax = cp[3].x - cp[0].x - cx - bx;
    cy = 3.0 * (cp[1].y - cp[0].y);
    by = 3.0 * (cp[2].y - cp[1].y) - cy;
    ay = cp[3].y - cp[0].y - cy - by;

    tSquared = t * t;
    tCubed = tSquared * t;
    result = {
      x: 0,
      y: 0,
    };
    result.x = ax * tCubed + bx * tSquared + cx * t + cp[0].x;
    result.y = ay * tCubed + by * tSquared + cy * t + cp[0].y;
    return result;
  }

  //仿真随机带曲线滑动
  //qx, qy, zx, zy, time 代表起点x,起点y,终点x,终点y,过程耗时单位毫秒
  function swipeX(qx, qy, zx, zy, time) {
    var xxy = [time];
    var point = [];
    var dx0 = {
      x: qx,
      y: qy,
    };

    var dx1 = {
      x: random(qx - 100, qx + 100),
      y: random(qy, qy + 50),
    };
    var dx2 = {
      x: random(zx - 100, zx + 100),
      y: random(zy, zy + 50),
    };
    var dx3 = {
      x: zx,
      y: zy,
    };
    point.push(dx0);
    point.push(dx1);
    point.push(dx2);
    point.push(dx3);

    for (let i = 0; i < 1; i += 0.08) {
      xxyy = [
        parseInt(bezier_curves(point, i).x),
        parseInt(bezier_curves(point, i).y),
      ];

      xxy.push(xxyy);
    }

    gesture.apply(null, xxy);
  }
  var swipeUtils$3 = {
    swipeX: swipeX,
    swipeUp() {
      var configs = [
        [
          60,
          100,
          device.width / 2,
          (device.height / 10) * 5,
          device.width / 2,
          (device.height / 10) * 2,
        ],
        [
          40,
          60,
          device.width / 2,
          (device.height / 10) * 6,
          device.width / 2,
          (device.height / 10) * 3,
        ],
        [
          30,
          40,
          device.width / 2,
          (device.height / 10) * 7,
          device.width / 2,
          (device.height / 10) * 2,
        ],
        [
          1,
          30,
          device.width / 2,
          (device.height / 10) * 8,
          device.width / 2,
          (device.height / 10) * 5,
        ],
      ];
      for (var index = 0; index < configs.length; index++) {
        var config = configs[index];
        if (randomUtils$6.possible(config[0], config[1])) {
          this.swipeX(
            config[2] + randomUtils$6.getRandom(0, 30),
            config[3] + randomUtils$6.getRandom(0, 30),
            config[4] + randomUtils$6.getRandom(0, 30),
            config[5] + randomUtils$6.getRandom(0, 30),
            randomUtils$6.getRandom(350, 800)
          );
          return;
        }
      }
    },
    swipeDown() {
      var configs = [
        [
          60,
          100,
          device.width / 3,
          device.height / 2,
          device.width / 3 + 20,
          device.height / 2 - device.height / 5,
        ],
        [
          40,
          60,
          device.width / 5,
          device.height / 3,
          device.width / 5 + 20,
          device.height / 3 - device.height / 6,
        ],
        [
          30,
          40,
          (device.width / 7) * 2,
          device.height / 4,
          (device.width / 7) * 2 + 20,
          device.height / 4 - device.height / 7,
        ],
        [
          1,
          30,
          device.width / 9,
          device.height / 5,
          device.width / 9 + 20,
          device.height / 5 - device.height / 8,
        ],
      ];
      for (var index = 0; index < configs.length; index++) {
        var config = configs[index];
        if (randomUtils$6.possible(config[0], config[1])) {
          this.swipeX(
            config[4] + randomUtils$6.getRandom(0, 30),
            config[5] + randomUtils$6.getRandom(0, 30),
            config[2] + randomUtils$6.getRandom(0, 30),
            config[3] + randomUtils$6.getRandom(0, 30),
            randomUtils$6.getRandom(200, 500)
          );
          return;
        }
      }
    },
    swipeRead(span, maxUp) {
      span = span || 60;
      span = randomUtils$6.getRandom(span, span + 5);
      maxUp = randomUtils$6.getRandom(maxUp, maxUp + 2);
      var startTime = Date.now();
      var count = 0;
      while (true) {
        count++;
        if (count < maxUp) {
          if (count % 3 == 0) {
            logUtils$7.info("SR:", "向上滑动一次");
          }
          this.swipeUp();
        } else {
          if (randomUtils$6.possible(1, 90)) {
            if (count % 3 == 0) {
              logUtils$7.info("SR:", "向上滑动一次");
            }
            this.swipeUp();
          } else {
            if (count % 3 == 0) {
              logUtils$7.info("SR:", "向下滑动一次");
            }
            this.swipeDown();
          }
        }
        sleep(randomUtils$6.getRandom(1.5, 3, 1000));
        var hasRead = timeUtils$4.hasExec(startTime);
        if (count % 5 == 0) {
          logUtils$7.info("SR:", hasRead, "/", span);
        }
        if (hasRead >= span) {
          if (count % 5 != 0) {
            logUtils$7.info("SR:", hasRead, "/", span);
          }
          break;
        }
      }
    },
    swipeVideo() {
      var configs = [
        [
          60,
          100,
          device.width / 2,
          (device.height / 10) * 7,
          device.width / 2 + 20,
          (device.height / 10) * 1 - 50,
        ],
        [
          40,
          60,
          device.width / 2,
          (device.height / 10) * 7,
          device.width / 2 + 20,
          (device.height / 10) * 1.5 - 80,
        ],
        [
          30,
          40,
          device.width / 2,
          (device.height / 10) * 8,
          device.width / 2 + 20,
          (device.height / 10) * 1.8 - 80,
        ],
        [
          1,
          30,
          device.width / 2,
          (device.height / 10) * 8.5,
          device.width / 2 + 20,
          (device.height / 10) * 2 - 80,
        ],
      ];
      for (var index = 0; index < configs.length; index++) {
        var config = configs[index];
        if (randomUtils$6.possible(config[0], config[1])) {
          this.swipeX(
            config[2] + randomUtils$6.getRandom(0, 30),
            config[3] + randomUtils$6.getRandom(0, 30),
            config[4] + randomUtils$6.getRandom(0, 30),
            config[5] + randomUtils$6.getRandom(0, 30),
            randomUtils$6.getRandom(350, 800)
          );
          return;
        }
      }
    },
  };

  var ocrCharMap$2 = {
    搜: ['嫂', '樓', '接', '楼'],
    赚: ['廉', '嫌', '賺', '兼'],
    看: ['着', '春', '香'],
    文: ['女'],
    章: ['拿'],
    钱: ['线'],
    觉: ['党'],
    户: ['戶'],
    索: ['素'],
    开: ['升', '研'],
    金: ['全'],
    积: ['枳'],
    币: ['市'],
    现: ['現'],
    领: ['領', '颌'],
    读: ['渎'],
    额: ['額'],
    取: ['驭'],
    视: ['规', '初'],
    享: ['亨'],
    兑: ['兌'],
    提: ['堤'],
    体: ['休'],
    才: ['オ'],
    街: ['衔'],
    城: ['械'],
    间: ['闻'],
    来: ['來'],
    幕: ['慕'],
    十: ['+'],
    已: ['己'],
    己: ['已'],
    摄: ['攝'],
    获: ['狭'],
    惊: ['悚'],
  };
  var ocrCharMap_1 = ocrCharMap$2;

  var randomUtils$5 = randomUtils$9;
  var swipeUtils$2 = swipeUtils$3;
  var logUtils$6 = logUtils$9;
  var configUtils$2 = configUtils$5;
  var ocrCharMap$1 = ocrCharMap_1;
  var http$ = configUtils$2.getConfig ('log', 'http', false);

  if (!requestScreenCapture ()) {
    toastLog ('请求截图权限失败');
    exit ();
  }
  function toArray (arrLike) {
    var array = [];
    for (var index = 0; index < arrLike.length; index++) {
      array.push (arrLike[index]);
    }
    return array;
  }
  function getCaptureImg () {
    var startTime = Date.now ();
    var showing = console.showing;
    if (http$) {
      if (showing) {
        console.hide ();
        sleep (0.1 * 1000);
      }
    }
    var captureImg = captureScreen ();
    if (http$) {
      if (showing) {
        console.show ();
      }
    }
    if (!captureImg) {
      toastLog ('截图失败');
    }
    var endTime = Date.now ();
    var hasExec = (endTime - startTime) / 1000;
    if (hasExec > 1) {
      logUtils$6.info ('GCI: 截图耗费-' + hasExec + '-s');
    }
    return captureImg;
  }
  function getOcrResults () {
    var captureImg = getCaptureImg ();
    var ocrResults = toArray (gmlkit.ocr (captureImg, 'zh').toArray (3));
    setTimeout (() => {
      captureImg.recycle ();
    });
    return ocrResults;
  }
  var ocrUtils$3 = {
    getRegExpConfig (content) {
      var regExpStr = content
        .split ('')
        .map (function (item) {
          var match = ocrCharMap$1[item];
          var piece = match
            ? '[' + match.concat (item).join ('') + ']+'
            : '[' + item + ']+';
          return piece + `\\s*`;
        })
        .join ('');
      return {
        text: content,
        regExp: new RegExp (regExpStr, 'gi'),
      };
    },
    captureAndLog () {
      var ocrResults = getOcrResults ();
      this.logOcrResults (ocrResults);
    },
    logOcrResults (ocrResults) {
      logUtils$6.info (
        'LOR:',
        '\n',
        ocrResults.map (item => item.text).join ('\n')
      );
    },
    ocrResultsExist (ocrResults, regExpConfig) {
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        if (regExpConfig.regExp.test (ocrResult.text)) {
          return ocrResult;
        }
      }
      return false;
    },
    regExpConfigExist (ocrResults, regExpConfigs) {
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        for (var index2 = 0; index2 < regExpConfigs.length; index2++) {
          var regExpConfig = regExpConfigs[index2];
          if (regExpConfig.regExp.test (ocrResult.text)) {
            return ocrResult;
          }
        }
      }
      return false;
    },
    regExpConfigExistSome (ocrResults, regExpConfigs) {
      var results = [];
      for (var index = 0; index < ocrResults.length; index++) {
        var ocrResult = ocrResults[index];
        for (var index2 = 0; index2 < regExpConfigs.length; index2++) {
          var regExpConfig = regExpConfigs[index2];
          if (regExpConfig.regExp.test (ocrResult.text)) {
            results.push (ocrResult);
          }
        }
      }
      return results;
    },
    captureExistsText (content, logOcrResults, ignoreLog) {
      var regExpConfig = this.getRegExpConfig (content);
      var ocrResults = getOcrResults ();
      var ocrResult = this.ocrResultsExist (ocrResults, regExpConfig);
      if (ocrResult) {
        if (!ignoreLog) {
          logUtils$6.info ('CET:', '找到', regExpConfig.text, '/', ocrResult.text);
        }
        return ocrResult;
      } else {
        if (logOcrResults) {
          this.logOcrResults (ocrResults);
        }
        return false;
      }
    },
    captureExistsOneText (contents, logOcrResults, ignoreLog) {
      if (!Array.isArray (contents)) {
        contents = [contents];
      }
      var ocrResults = getOcrResults ();
      var regExpConfigs = contents.map (content =>
        this.getRegExpConfig (content)
      );
      var ocrResult = this.regExpConfigExist (ocrResults, regExpConfigs);
      if (ocrResult) {
        if (!ignoreLog) {
          logUtils$6.info ('CEOT:', '找到', contents.join (','), '/', ocrResult.text);
        }
        return ocrResult;
      } else {
        logUtils$6.info ('CEOT:', '没找到', contents.join (','));
        if (logOcrResults) {
          this.logOcrResults (ocrResults);
        }
        return false;
      }
    },
    captureExistsSomeText (contents, logOcrResults, ignoreLog) {
      if (!Array.isArray (contents)) {
        contents = [contents];
      }
      var ocrResults = getOcrResults ();
      var regExpConfigs = contents.map (content =>
        this.getRegExpConfig (content)
      );
      var results = this.regExpConfigExistSome (ocrResults, regExpConfigs);
      if (results.length > 0) {
        if (!ignoreLog) {
          logUtils$6.info (
            'CEOT:',
            '找到',
            contents.join (','),
            '/',
            results.map (item => item.text).join (',')
          );
        }
        return results;
      } else {
        logUtils$6.info ('CEOT:', '没找到', contents.join (','));
        if (logOcrResults) {
          this.logOcrResults (ocrResults);
        }
        return false;
      }
    },

    captureExistsAllText (contents, logOcrResults, ignoreLog) {
      if (!Array.isArray (contents)) {
        contents = [contents];
      }
      var ocrResults = getOcrResults ();
      var regExpConfigs = contents.map (content =>
        this.getRegExpConfig (content)
      );
      var findResults = [];
      for (var index = 0; index < regExpConfigs.length; index++) {
        var regExpConfig = regExpConfigs[index];
        var ocrResult = this.ocrResultsExist (ocrResults, regExpConfig);
        if (ocrResult) {
          findResults.push (ocrResult);
        }
      }
      if (findResults.length == contents.length) {
        if (!ignoreLog) {
          logUtils$6.info (
            'CEAT:',
            '找到',
            '\n',
            contents.join (','),
            '\n',
            findResults.map (item => item.text).join (',')
          );
        }
        return true;
      } else {
        logUtils$6.info ('CEAT:', '没找到', contents.join (','));
        if (logOcrResults) {
          this.logOcrResults (ocrResults);
        }
        return false;
      }
    },
    scrollAndFindSome (contents, logOcrResults, ignoreLog, maxScrollCount) {
      maxScrollCount = maxScrollCount || 10;
      for (var index = 0; index < maxScrollCount; index++) {
        var results = this.captureExistsSomeText (
          contents,
          logOcrResults,
          ignoreLog
        );
        if (results.length > 0) {
          return results;
        }
        sleep (randomUtils$5.getRandom (1.5, 2, 1000));
        swipeUtils$2.swipeUp ();
      }
      return [];
    },
  };

  var TEXT_MAX_SEARCH_TIME = 10000; //搜索控件时超时时间 http://doc.autoxjs.com/#/widgetsBasedAutomation?id=uiselectorfindonetimeout
  var clickUtils$3 = clickUtils$5;
  var logUtils$5 = logUtils$9;
  var textUtils$4 = {
    inScreen(TextUI) {
      var bounds = TextUI.bounds();
      var left = bounds.left;
      var right = bounds.right;
      var top = bounds.top;
      var bottom = bounds.bottom;
      return (
        left >= 0 && right <= device.width && top >= 0 && bottom <= device.height
      );
    },
    getTextUI(TextUI) {
      if (!TextUI) {
        return false;
      }
      return this.inScreen(TextUI) ? TextUI : false;
    },
    existsText(content, ignoreLog) {
      if (text(content).exists()) {
        var TextUI = this.getTextUI(text(content).findOne(TEXT_MAX_SEARCH_TIME));
        if (!ignoreLog && TextUI) {
          logUtils$5.info("ET", "找到：", content, "/", TextUI.text());
        }
        return TextUI;
      } else {
        return false;
      }
    },
    existsTextStartsWith(content, ignoreLog) {
      if (textStartsWith(content).exists()) {
        var TextUI = this.getTextUI(
          textStartsWith(content).findOne(TEXT_MAX_SEARCH_TIME)
        );
        if (!ignoreLog && TextUI) {
          logUtils$5.info("ETSW", "找到：", content, "/", TextUI.text());
        }
        return TextUI;
      } else {
        return false;
      }
    },
    existsTextEndsWith(content, ignoreLog) {
      if (textEndsWith(content).exists()) {
        var TextUI = this.getTextUI(
          textEndsWith(content).findOne(TEXT_MAX_SEARCH_TIME)
        );
        if (!ignoreLog && TextUI) {
          logUtils$5.info("ETEW", "找到：", content, "/", TextUI.text());
        }
        return TextUI;
      } else {
        return false;
      }
    },
    existsTextMatches(contentRegExp, ignoreLog) {
      if (textMatches(contentRegExp).exists()) {
        var TextUI = this.getTextUI(
          textMatches(contentRegExp).findOne(TEXT_MAX_SEARCH_TIME)
        );
        if (TextUI) {
          if (!ignoreLog) {
            logUtils$5.info("ETM", "找到：", contentRegExp, "/", TextUI.text());
          }
          return TextUI;
        } else {
          return false;
        }
      } else {
        return false;
      }
    },
  };
  var clickMethods = [
    ["existsText", "clickText"],
    ["existsTextStartsWith", "clickTextStartsWith"],
    ["existsTextEndsWith", "clickTextEndsWith"],
    ["existsTextMatches", "clickTextMatches"],
  ];
  var oneMethods = [
    ["existsText", "existsOneText"],
    ["existsTextStartsWith", "existsOneTextStartsWith"],
    ["existsTextEndsWith", "existsOneTextEndsWith"],
    ["existsTextMatches", "existsOneTextMatches"],
  ];
  var allMethods = [
    ["existsText", "existsAllText"],
    ["existsTextStartsWith", "existsAllTextStartsWith"],
    ["existsTextEndsWith", "existsAllTextEndsWith"],
    ["existsTextMatches", "existsAllTextMatches"],
  ];
  clickMethods.forEach(function (method) {
    var oldMethod = method[0];
    var newMethod = method[1];
    textUtils$4[newMethod] = function (content, ignoreLog) {
      var TextUI = this[oldMethod](content, true);
      if (TextUI) {
        if (!ignoreLog) {
          logUtils$5.info(newMethod, "找到:", content, "/", TextUI.text());
        }
        clickUtils$3.clickTextUI(TextUI);
        return TextUI;
      } else {
        return false;
      }
    };
    return false;
  });
  oneMethods.forEach(function (method) {
    var oldMethod = method[0];
    var newMethod = method[1];
    textUtils$4[newMethod] = function (contents, ignoreLog) {
      if (!Array.isArray(contents)) {
        contents = [contents];
      }
      for (var index = 0; index < contents.length; index++) {
        var content = contents[index];
        var TextUI = this[oldMethod](content, true);
        if (TextUI) {
          if (!ignoreLog) {
            logUtils$5.info(
              newMethod,
              "找到",
              contents.join("|"),
              "/",
              TextUI.text()
            );
          }
          return TextUI;
        }
      }
      return false;
    };
  });
  allMethods.forEach(function (method) {
    var oldMethod = method[0];
    var newMethod = method[1];
    var findText = [];
    textUtils$4[newMethod] = function (contents, ignoreLog) {
      if (!Array.isArray(contents)) {
        contents = [contents];
      }
      for (var index = 0; index < contents.length; index++) {
        var content = contents[index];
        var TextUI = this[oldMethod](content, true);
        if (!TextUI) {
          return false;
        } else {
          findText.push(TextUI.text());
        }
      }
      if (!ignoreLog) {
        logUtils$5.info(
          newMethod,
          "全部找到",
          contents.join("|"),
          "/",
          findText.join("|")
        );
      }
      return true;
    };
  });

  var textUtils_1 = textUtils$4;

  var fmtUtils$3 = {
    getNumber(text$) {
      var reg = /\d+/g;
      var match = text$.match(reg);
      if (match) {
        return match[0] || 0;
      } else {
        return 0;
      }
    },
    msg() {
      var join = [].join;
      return join.call(arguments, "");
    },
  };

  var pauseUtils$2 = {
    pause(msg, interval) {
      interval = interval || 8;
      while (true) {
        var value = dialogs.confirm(msg);
        if (value) {
          return;
        } else {
          sleep(interval * 1000);
        }
      }
    },
  };

  var appUtils$2 = appUtils$3;
  var clickUtils$2 = clickUtils$5;
  var logUtils$4 = logUtils$9;
  var ocrUtils$2 = ocrUtils$3;
  var randomUtils$4 = randomUtils$9;
  var swipeUtils$1 = swipeUtils$3;
  var textUtils$3 = textUtils_1;
  var timeUtils$3 = timeUtils$5;
  var fmtUtils$2 = fmtUtils$3;
  var pauseUtils$1 = pauseUtils$2;
  var configUtils$1 = configUtils$5;
  var ocrCharMap = ocrCharMap_1;

  function existContent$2 (content) {
    var TextUI = textUtils$3.existsTextStartsWith (content);
    if (TextUI) {
      return {
        type: 0,
        result: TextUI,
      };
    }
    var TextOCR = ocrUtils$2.captureExistsText (content);
    if (TextOCR) {
      return {
        type: 1,
        result: TextOCR,
      };
    }
    return null;
  }
  function existOneContent$1 (contents) {
    if (!Array.isArray (contents)) {
      contents = [contents];
    }
    for (var index = 0; index < contents.length; index++) {
      var content = contents[index];
      var result = existContent$2 (content);
      if (result) {
        return result;
      }
    }
    return false;
  }
  function clickContent$3 (content, logError) {
    var result = false;
    var TextUI = textUtils$3.existsTextStartsWith (content);
    if (TextUI) {
      clickUtils$2.clickTextUI (TextUI);
      result = true;
      return result;
    }
    var TextOCR = ocrUtils$2.captureExistsText (content, logError);
    if (TextOCR) {
      clickUtils$2.clickTextOCR (TextOCR);
      result = true;
      return result;
    }
    return result;
  }
  function clickOneContent (contents) {
    if (!Array.isArray (contents)) {
      contents = [contents];
    }
    for (var index = 0; index < contents.length; index++) {
      var content = contents[index];
      if (clickContent$3 (content)) {
        return true;
      }
    }
    return false;
  }

  utils.appUtils = appUtils$2;
  utils.clickUtils = clickUtils$2;
  utils.logUtils = logUtils$4;
  utils.ocrUtils = ocrUtils$2;
  utils.randomUtils = randomUtils$4;
  utils.swipeUtils = swipeUtils$1;
  utils.textUtils = textUtils$3;
  utils.timeUtils = timeUtils$3;
  utils.fmtUtils = fmtUtils$2;
  utils.pauseUtils = pauseUtils$1;
  utils.configUtils = configUtils$1;
  utils.ocrCharMap = ocrCharMap;
  utils.existContent = existContent$2;
  utils.existOneContent = existOneContent$1;
  utils.clickContent = clickContent$3;
  utils.clickOneContent = clickOneContent;

  var adCommon$3 = {
    maxAdCount: 0,
    adCount: 0,
  };

  var {
    randomUtils: randomUtils$3,
    textUtils: textUtils$2,
    timeUtils: timeUtils$2,
    clickUtils: clickUtils$1,
    ocrUtils: ocrUtils$1,
    fmtUtils: fmtUtils$1,
    appUtils: appUtils$1,
    pauseUtils,
    logUtils: logUtils$3,
    clickContent: clickContent$2,
    configUtils,
  } = utils;
  var adCommon$2 = adCommon$3;
  var manual = configUtils.getConfig ('ad', 'manual', false);
  var adType1$1 = {
    watchAd (span, handleNextAd) {
      this.appName = '悟空浏览器';
      this.span = span;
      this.handleNextAd = handleNextAd;
      var startTime = Date.now ();
      var lastStartTime = Date.now ();
      var count = 0;
      var hasCheckDetail = false;
      adCommon$2.adCount++;
      logUtils$3.info ('第', adCommon$2.adCount, '/', adCommon$2.maxAdCount, '个广告');
      while (true) {
        count++;
        var hasExec = timeUtils$2.hasExec (startTime);
        if (count % 5 == 0) {
          logUtils$3.info ('已经观看', hasExec, '/', this.span);
        }
        if (!hasCheckDetail) {
          if (this.checkDetail ()) {
            hasCheckDetail = true;
            this.span = this.span + 45;
          }
        }
        if (hasExec > 20 && parseInt (timeUtils$2.hasExec (lastStartTime)) > 10) {
          if (this.isOver ()) {
            this.stopAd ();
            break;
          } else {
            lastStartTime = Date.now ();
          }
        }
        if (hasExec > this.span) {
          if (count % 5 != 0) {
            logUtils$3.info ('已经观看', hasExec, '/', this.span, '将执行关闭广告');
          }
          sleep (randomUtils$3.getRandom (2, 15, 1000));
          this.stopAd ();
          break;
        }
        sleep (2 * 1000);
      }
    },
    stopAd () {
      for (var index = 0; index < 2; index++) {
        back ();
        sleep (randomUtils$3.getRandom (1.5, 2, 1000));
        var exitContents = [
          //prettier-disable
          '坚持退出',
        ];
        var hasNextContents = [
          //prettier-disable
          '看视频再得',
          '再看一个',
          '再看1个',
        ];
        if (adCommon$2.adCount >= adCommon$2.maxAdCount) {
          var TextUI = textUtils$2.existsOneTextStartsWith (exitContents);
          if (TextUI) {
            clickUtils$1.clickTextUI (TextUI);
            sleep (randomUtils$3.getRandom (1.5, 2, 1000));
            return;
          }
        } else {
          var TextUI = textUtils$2.existsOneTextStartsWith (hasNextContents);
          if (TextUI) {
            var text$ = TextUI.text ();
            var goldNumber = fmtUtils$1.getNumber (text$);
            logUtils$3.info ('发现广告:', text$, goldNumber);
            if (goldNumber > 500) {
              clickUtils$1.clickTextUI (TextUI);
              sleep (randomUtils$3.getRandom (1.5, 2, 1000));
              this.handleNextAd && this.handleNextAd ();
              return;
            }
            if (manual) {
              if (goldNumber < 500 && goldNumber > 100) {
                pauseUtils.pause ('广告金币小于500，需要人工干预');
                pauseUtils.pause ('是否已经开始下一个广告？');
                sleep (randomUtils$3.getRandom (1, 5, 2, 1000));
                this.handleNextAd && this.handleNextAd ();
                return;
              }
            }
            var TextUI = textUtils$2.existsOneTextStartsWith (exitContents);
            if (TextUI) {
              clickUtils$1.clickTextUI (TextUI);
              sleep (randomUtils$3.getRandom (1.5, 2, 1000));
              return;
            }
          }
        }
        if (!this.inAd ()) {
          logUtils$3.info ('没有广告，退出');
          return;
        }
      }
    },
    inAd () {
      var contents = [
        //prettier-disable
        '广告',
      ];
      var TextUI = textUtils$2.existsOneTextStartsWith (contents);
      if (TextUI) {
        return TextUI;
      }
      // var TextOCR = ocrUtils.captureExistsOneText (contents);
      // if (TextOCR) {
      //   return TextOCR;
      // }
      return false;
    },
    isOver () {
      var result = textUtils$2.existsTextMatches (/\d{1,3}s/);
      if (!result) {
        logUtils$3.info ('没找到**s,判断广告结束了');
        return true;
      } else {
        logUtils$3.info ('找到**s,判断广告正在播放');
        return false;
      }
    },
    checkDetail () {
      var content = '点击视频';
      if (clickContent$2 (content)) {
        sleep (randomUtils$3.getRandom (2, 3, 1000));
        appUtils$1.open (this.appName);
        sleep (randomUtils$3.getRandom (2, 3, 1000));
        if (this.checkOpen ()) {
          back ();
          sleep (randomUtils$3.getRandom (2, 3, 1000));
        } else {
          sleep (randomUtils$3.getRandom (15, 30, 1000));
        }
        back ();
        sleep (randomUtils$3.getRandom (2, 3, 1000));
        return true;
      }
      if (this.checkOpen ()) {
        return true;
      }
      return false;
    },
    checkOpen () {
      var content = '立即打开';
      if (clickContent$2 (content)) {
        sleep (randomUtils$3.getRandom (3, 5, 1000));
        var content = '允许';
        if (clickContent$2 (content)) {
          sleep (randomUtils$3.getRandom (3, 5, 1000));
        }
        sleep (randomUtils$3.getRandom (10, 20, 1000));
        appUtils$1.open (this.appName);
        return true;
      }
      return false;
    },
  };

  var {
    randomUtils: randomUtils$2,
    textUtils: textUtils$1,
    timeUtils: timeUtils$1,
    clickUtils,
    ocrUtils,
    fmtUtils,
    appUtils,
    logUtils: logUtils$2,
    clickContent: clickContent$1,
  } = utils;
  var adCommon$1 = adCommon$3;
  var adType2$1 = {
    watchAd(span, handleNextAd) {
      this.appName = "悟空浏览器";
      this.span = span;
      this.handleNextAd = handleNextAd;
      var startTime = Date.now();
      var count = 0;
      var hasCheckFuDai = false;
      adCommon$1.adCount++;
      logUtils$2.info("第", adCommon$1.adCount, "/", adCommon$1.maxAdCount, "个广告");
      while (true) {
        count++;
        var hasExec = timeUtils$1.hasExec(startTime);
        if (count % 5 == 0) {
          logUtils$2.info("已经观看", hasExec, "/", this.span);
        }
        if (!hasCheckFuDai) {
          if (this.checkFuDai()) {
            hasCheckFuDai = true;
            this.span = this.span + 20;
          }
        }
        if (count >= 4 && this.isOver()) {
          this.stopAd();
          break;
        }
        if (hasExec > this.span) {
          if (count % 5 != 0) {
            logUtils$2.info("已经观看", hasExec, "/", this.span, "将执行关闭广告");
          }
          this.stopAd();
          break;
        }
        sleep(2 * 1000);
      }
    },
    stopAd() {
      for (var index = 0; index < 5; index++) {
        var content = "跳过";
        if (clickContent$1(content)) {
          sleep(randomUtils$2.getRandom(3, 5, 1000));
        } else {
          return true;
        }
      }
    },
    inAd() {
      var contents = [
        //prettier-disable
        "反馈",
        "广告",
      ];
      var TextUI = textUtils$1.existsOneTextStartsWith(contents);
      if (TextUI) {
        return TextUI;
      }
      var TextOCR = ocrUtils.captureExistsOneText(contents);
      if (TextOCR) {
        return TextOCR;
      }
      return false;
    },
    isOver() {
      var contents = ["领取成功", "跳过"];
      var TextOCR = ocrUtils.captureExistsOneText(contents);
      if (TextOCR) {
        return true;
      }
      sleep(10 * 1000);
      var TextUI = textUtils$1.existsOneTextStartsWith(contents);
      if (TextUI) {
        return true;
      }
      return false;
    },
    checkFuDai() {
      var content = "点击福袋";
      if (clickContent$1(content)) {
        sleep(randomUtils$2.getRandom(3, 5, 1000));
        return true;
      }
      return false;
    },
  };

  var {
    timeUtils,
    logUtils: logUtils$1,
    randomUtils: randomUtils$1,
    swipeUtils,
    existContent: existContent$1,
  } = utils;
  var adType3$1 = {
    watchAd(span, handleNextAd) {
      this.span = span;
      this.handleNextAd = handleNextAd;
      this.init();
    },
    stopAd() {
      sleep(randomUtils$1.getRandom(2, 3, 1000));
      back();
      sleep(randomUtils$1.getRandom(2, 3, 1000));
    },
    init() {
      var startTime = Date.now();
      var lastStartTime = Date.now();
      var count = 0;
      while (true) {
        count++;
        if (randomUtils$1.possible(15, 100)) {
          swipeUtils.swipeUp();
        } else {
          swipeUtils.swipeDown();
        }
        sleep(randomUtils$1.getRandom(3, 5, 1000));
        if (count % 5 == 0) {
          logUtils$1.info("已经看了" + hasExec + "/" + this.span);
        }
        var hasExec = timeUtils.hasExec(startTime);

        if (hasExec > 20 && timeUtils.hasExec(lastStartTime) > 10) {
          if (this.isOver()) {
            this.stopAd();
            break;
          } else {
            lastStartTime = Date.now();
          }
        }

        if (hasExec > this.span) {
          if (count % 5 != 0) {
            logUtils$1.info("已经看了" + hasExec + "/" + this.span);
          }
          this.stopAd();
          break;
        }
      }
    },
    isOver() {
      var content = "任务已完成";
      if (existContent$1(content)) {
        return true;
      }
      return false;
    },
  };

  var {
    randomUtils,
    textUtils,
    logUtils,
    clickContent,
    existOneContent,
    existContent,
  } = utils;
  var adCommon = adCommon$3;
  var adType1 = adType1$1;
  var adType2 = adType2$1;
  var adType3 = adType3$1;
  var MAX_AD_INTERVAL = 45;
  var wuKong = {
    startWatchAd(maxAdCount) {
      adCommon.adCount = 0;
      adCommon.maxAdCount = maxAdCount || 20;
      this.normal = true;
      this.getAdType();
    },
    getAdType() {
      var span = randomUtils.getRandom(MAX_AD_INTERVAL, MAX_AD_INTERVAL + 5);
      for (var index = 0; index < 5; index++) {
        sleep(2 * 1000);
        if (this.isType1()) {
          logUtils.info("adType:1");
          adType1.watchAd(span, () => {
            this.getAdType();
          });
          return;
        }
        sleep(2 * 1000);
        if (this.isType2()) {
          logUtils.info("adType:2");
          adType2.watchAd(span, () => {
            this.getAdType();
          });
          return;
        }
        if (this.isType3()) {
          logUtils.info("adType:3");
          adType3.watchAd(span, () => {
            this.getAdType();
          });
          return;
        }
      }
      logUtils.info("wuKong", "未知的adType");
      this.normal = false;
    },
    isType3() {
      var content = "秒后得";
      if (existContent(content)) {
        return true;
      }
      return false;
    },
    isType2() {
      var content = "反馈";
      if (!existContent(content)) {
        return false;
      }
      if (textUtils.existsTextMatches(/\d{1,3}s/)) {
        return false;
      }
      return true;
    },
    isType1() {
      var content = "广告";
      if (!existContent(content)) {
        return false;
      }
      var content = "关闭";
      if (!existContent(content)) {
        return false;
      }
      if (!textUtils.existsTextMatches(/\d{1,3}s/)) {
        return false;
      }
      return true;
    },
  };

  var ad = wuKong;
  ad.startWatchAd(20);

  return adTest;

})();
